#!/usr/bin/perl
package Check;
push (@INC , "D:/workplace/Apache2/mason/Model");
use strict;
use warnings;

use Session;

my %session_config = (
    Store     => 'DB_File',
    Lock      => 'Null',
    Generate  => 'MD5',
    Serialize => 'Storable',
    # DB_File backend option
    FileName  => 'sessions.db',
);

# make a fresh session for a first-time visitor
our $session = new Session undef, %session_config;

sub new{
    my $class = shift;

    my $self = bless {}, $class;

    return $self;
};

sub get{
    return $session->get('id');
};

sub set{
    my ($self, $id) = @_;

    $session->set('id' => $id);

    return 1;
};

sub check{
    my ($self) = @_;
    if(!exists($session->get('id')))
    {
        $m->redirect('/mason/View/login');
    }else{
        return 1;
    }
};

sub leave{
    my ($self) = @_;
    $session->clear();
};

1;